using System;
using System.Collections.Generic;
using System.Linq;
using MathSharp;

namespace System {
	static class IEnumerableExtension {
		/// <summary>
		/// возвращает фрагмент перечисления от и до указаной позиции
		/// </summary>
		public static ListFragment<T> GetFragment<T>(this IEnumerable<T> e, int from, int to) {
			return new ListFragment<T>(e, from, to);
		}
	}
	
	static class IListExtension {
		public static int GetOriginalLineSmarts<T>(this IList<T> list, int line) {
			if (list is ListFragment<T>)
				return ((ListFragment<T>)list).GetOriginalLine(line);
			else
				return line;
		}
	}
	
	static class StringExtension {
		public static string format(this string format, params object[] args) {
			return string.Format(format, args);
		}
		
		public static string Join(this IEnumerable<string> e, string glue) {
			return e.Aggregate((s1,s2) => string.Concat(s1, glue, s2));
		}

		public static bool IsNullOrEmpty(this string s) {
			return string.IsNullOrEmpty(s);
		}

		public static bool IsNullOrWhiteSpace(this string s) {
			return string.IsNullOrWhiteSpace(s);
		}
	}
	
	static class TypeExtension {
		public static bool IsAnyInteger(this Type targetType) {
			return targetType == typeof (int)
					|| targetType == typeof (uint)
					|| targetType == typeof (long)
					|| targetType == typeof (ulong)
					|| targetType == typeof (short)
					|| targetType == typeof (ushort);
		}
		
		public static bool IsAnyFloatPointNumber(this Type targetType) {
			return targetType == typeof (float)
					|| targetType == typeof (double)
					|| targetType == typeof (decimal);
		}
		
		public static bool IsAnyNumeric(this Type targetType) {
			return targetType.IsAnyInteger() || targetType.IsAnyFloatPointNumber();
		}
	}
}